package com.panda.controller;/**
 * @author 乐于吕
 * * @date 2024/10/16
 */

import com.panda.entity.Role;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: 乐于吕
 * @CreateTime: 2024-10-16
 * @Description:
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Value("${server.port}")
    private String port;

    @GetMapping("/m1")
    public String method1(HttpServletRequest request) {
//        try {
//            Thread.sleep(3000);
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
        String color = request.getParameter("color");
        return "roleController method1 success port: " + port +" color: "+ color;
    }

    @GetMapping("/m2")
    public String method2(Integer id) {
        return "roleController method2 success port: " + port + " id: " + id;
    }

    @GetMapping("/m3/{id}")
    public String method3(@PathVariable("id") Integer id) {
        return "roleController method3 success port: " + port + " id: " + id;
    }

    //    http://localhost:8544/role/m4?id=1&name=2$description=管理员
    @GetMapping("/m4")
    public String method4(Role role) {
        System.out.println("role" + role);
        return "roleController method4 success port: " + port;
    }

    @PostMapping("/m5")
    public String method5(@RequestBody Role role) {
        System.out.println("role" + role);
        return "roleController method5 success port: " + port;
    }

    @PostMapping("/m6")
    public String method6(@RequestBody List<Integer> ids) {
        System.out.println("ids" + ids);
        return "roleController method6 success port: " + port;
    }

    @PostMapping("/m7")
    public Role method7() {
        Role role = new Role();
        role.setId(1);
        role.setRoleName("管理员");
        role.setDescription("管理员");
        System.out.println("role" + role);
        return role;
    }

    @PostMapping("/m8")
    public List<Role> method8() {
        Role role = new Role();
        role.setId(1);
        role.setRoleName("管理员");
        role.setDescription("管理员");
        List<Role> list = Arrays.asList(role, role, role);
        return list;
    }


}
